const http = require("http");
var data = require("./users.json");
const sto = require("./把字符串转换成对象");
const server = http.createServer((req, res) => {
  res.setHeader("content-type", "text/html;charset=utf-8");
  if (req.url !== "/favicon.ico") {
    let { username, pwd } = sto(req.url);
    var res1 = data.find(
      (item) => item.username == username && item.pwd == pwd
    );

    if (typeof res1 !== "undefined") {
      res.write("用户名和密码正确");
    } else {
      res.write("用户名或密码错误");
    }
  }

  res.end();
});

server.listen(8080);
